@extends('admin.layout')
@section('title', $title)
@section('content')
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                商品管理
                <small>商品预览信息</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 主页</a></li>
                <li><a href="#">商品</a></li>
                <li class="active">商品列表</li>
            </ol>
        </section>
        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">
                        <div class="box-header">
                            <div class="row">
                                <div class="col-xs-3">
                                    <button class="btn-lg">商品列表</button>
                                </div>
                                <div class="col-xs-6">

                                </div>
                                <div class="col-xs-3">
                                    <a href = "{{ asset('/admin/goods/goodsAdd') }}/{{ $pid }}" class="btn btn-block btn-success btn-lg">添加商品</a>
                                </div>
                            </div>


                        </div><!-- /.box-header -->
                        @if(session('info'))
                            <div class="alert alert-success alert-dismissable"
                                 id="info">
                                {{ session('info') }}
                            </div>
                        @endif
                        <div class="box-body">
                            <table id="example2" class="table table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>商品名称</th>
                                    <th>库存</th>
                                    <th>上架</th>
                                    <th>热卖</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($data as $k => $v)
                                    <tr>
                                        <td id="ids">{{ $v -> id}}</td>
                                        <td>{{ $v -> goodsname }}</td>
                                        <td>{{ $v -> goodsnum }}</td>
                                        <td class="sale">
                                            @if($v->is_onsale)
                                                是
                                            @else
                                                否
                                            @endif
                                        </td>
                                        <td class="hot">
                                            @if($v->hot_sale)
                                                是
                                            @else
                                                否
                                            @endif
                                        </td>
                                        <td>
                                            <a href="{{ url('/admin/goods/goodsDetail') }}/{{ $v->id }}">查看</a>
                                            <a href="{{ url('/admin/goods/goodsEdit') }}/{{ $v->id }}">编辑</a>
                                            <a href="{{ url('/admin/goods/plateDoDelete') }}/{{ $v->id }}">删除</a>
                                        </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                        </div><!-- /.box-body -->
                    </div><!-- /.box -->
                </div><!-- /.col -->
            </div><!-- /.row -->
        </section><!-- /.content -->
    </div><!-- /.content-wrapper -->
    <script type="text/javascript">
        window.onload = function () {
            setInterval(function () {
                $('#info').slideUp(1000);
            }, 3000)
//            单击修改售货信息
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
            $('.sale').on('click', function () {
                var t = $(this);
                var id = t.parent().find('#ids').html();
                $.ajax({
                    type: 'POST',
                    async: true,
                    url: "{{ url('/admin/goods/saleEdit') }}",
                    data: {id: id},
                    success: function (data) {
                        if (data == 1) {
                            t.html('是');
                        }
                        else if (data == 0) {
                            t.html('否');
                        }
                        else {
                            alert('修改失败');
                        }
                    },
                    error: function (data) {
                        alert('异常');
                    }
                })
            })
            $('.hot').on('click', function () {
                var t = $(this);
                var id = t.parent().find('#ids').html();
                $.ajax({
                    type: 'POST',
                    async: true,
                    url: "{{ url('/admin/goods/hotEdit') }}",
                    data: {id: id},
                    success: function (data) {
                        if (data == 1) {
                            t.html('是');
                        }
                        else if (data == 0) {
                            t.html('否');
                        }
                        else {
                            alert('修改失败');
                        }
                    },
                    error: function (data) {
                        alert('异常');
                    }
                })
            })
        }
    </script>
@endsection()
